#ifndef GAMEENGINE_GRAPHICS_MESHES_INDEXED_MESH_PRIMITIVES_H
#define GAMEENGINE_GRAPHICS_MESHES_INDEXED_MESH_PRIMITIVES_H

#include <GameEngine/Graphics/graphics_settings.h>

#include <GameEngine/Graphics/Meshes/surface_mesh.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif


//! Implementation of an indexed triangle
/*!
 *  An indexed triangle is a triangle whose vertices are defined by the vertex indexes, rather
 *  than the point themselves. The indexed triangle can optionally use normals or texture
 *  coordinates (which are also defined by indexes, rather than explicitely).
 */
class _Graphics_decl IndexedTrgl {

public:
	IndexedTrgl();
	IndexedTrgl(const IndexedTrgl& rhs);
	IndexedTrgl& operator=(const IndexedTrgl& rhs);
	virtual ~IndexedTrgl();

	void set_index(int point, SurfaceMesh::VertexIndex index);
	void set_cindex(int point, SurfaceMesh::TextureCoordinateIndex index);
	void set_nindex(int point, SurfaceMesh::NormalIndex index);

	SurfaceMesh::VertexIndex index1() const;
	SurfaceMesh::VertexIndex& index1();
	SurfaceMesh::VertexIndex index2() const;
	SurfaceMesh::VertexIndex& index2();
	SurfaceMesh::VertexIndex index3() const;
	SurfaceMesh::VertexIndex& index3();

	void use_texture_coordinates(bool use);
	bool has_texture_coordinates() const;
	SurfaceMesh::TextureCoordinateIndex cindex1() const;
	SurfaceMesh::TextureCoordinateIndex& cindex1();
	SurfaceMesh::TextureCoordinateIndex cindex2() const;
	SurfaceMesh::TextureCoordinateIndex& cindex2();
	SurfaceMesh::TextureCoordinateIndex cindex3() const;
	SurfaceMesh::TextureCoordinateIndex& cindex3();

	void use_normals(bool use);
	bool has_normals() const;
	SurfaceMesh::NormalIndex nindex1() const;
	SurfaceMesh::NormalIndex& nindex1();
	SurfaceMesh::NormalIndex nindex2() const;
	SurfaceMesh::NormalIndex& nindex2();
	SurfaceMesh::NormalIndex nindex3() const;
	SurfaceMesh::NormalIndex& nindex3();

protected:
	//! The first point of the triangle
	SurfaceMesh::VertexIndex index1_;
	//! The second point of the triangle
	SurfaceMesh::VertexIndex index2_;
	//! The third point of the triangle
	SurfaceMesh::VertexIndex index3_;

	//! Test if the triangle has texture coordinates
	bool coords_;
	//! The first texture coordinate of the triangle
	SurfaceMesh::TextureCoordinateIndex cindex1_;
	//! The second texture coordinate of the triangle
	SurfaceMesh::TextureCoordinateIndex cindex2_;
	//! The third texture coordinate of the triangle
	SurfaceMesh::TextureCoordinateIndex cindex3_;

	//! Test if the triangle has normals
	bool normals_;
	//! The first normal of the triangle
	SurfaceMesh::NormalIndex nindex1_;
	//! The second normal of the triangle
	SurfaceMesh::NormalIndex nindex2_;
	//! The third normal of the triangle
	SurfaceMesh::NormalIndex nindex3_;
};


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif

#endif
